From: Noah Meyerhans Date: Wed, 4 Feb 2026 16:09:21 +0000 (-0500) Subject: [PATCH] Correctly handle signed 32-bit time_t types X-Git-Tag: archive/raspbian/1%2.4.2+dfsg1-3+rpi1^2~5 X-Git-Url: https://dgit.raspbian.org/%22http:/www.example.com/cgi/%22https://%22%22/%22http:/www.example.com/cgi/%22https:/%22%22?a=commitdiff_plain;h=1ab315beec3ee80d673fabf9be2fc6cc927fad63;p=dovecot.git [PATCH] Correctly handle signed 32-bit time_t types Bug-Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1124541 Forwarded: no dovecot handles 32-bit time_t in a couple of different ways, but neither quite works currently. Setting TIME_T_MAX_BITS to 31 isn't correctly handled in places where time_t values are constructed, for example in io_loop_get_wait_time(). Similarly, setting TIME_T_MAX_BITS = 32 and defining TIME_T_SIGNED is not correctly handled by tm_is_too_large(). This change fixes tm_is_too_large() to set max_time to the correct maximum date representable by a signed 32-bit time_t. Closes: #1124541 Gbp-Pq: Name Correctly_handle_signed_32-bit_time_t_types.patch --- diff --git a/src/lib-imap/imap-date.c b/src/lib-imap/imap-date.c index c926293..df9d116 100644 --- a/src/lib-imap/imap-date.c +++ b/src/lib-imap/imap-date.c @@ -86,7 +86,11 @@ static bool tm_is_too_large(const struct tm *tm, time_t *max_time_r) if (max_time == 0) { #if TIME_T_MAX_BITS == 32 +#ifdef TIME_T_SIGNED + max_time = ((time_t)1 << TIME_T_MAX_BITS - 1) - 1; +#else max_time = 0xffffffffUL; +#endif #elif TIME_T_MAX_BITS == 64 max_time = 0xffffffffffffffffULL; #else diff --git a/src/lib-imap/test-imap-date.c b/src/lib-imap/test-imap-date.c index 5a2a364..94c1a82 100644 --- a/src/lib-imap/test-imap-date.c +++ b/src/lib-imap/test-imap-date.c @@ -15,7 +15,7 @@ static void test_imap_date(void) } tests[] = { { "01-Jan-1970", 0 }, { "19-Jan-2038", 2147472000 }, -#if TIME_T_MAX_BITS >= 32 +#if TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED) { "07-Feb-2106", 4294944000 }, #endif #if TIME_T_MAX_BITS >= 37 @@ -25,10 +25,10 @@ static void test_imap_date(void) { "31-Dec-9999", 253402214400LL }, #endif /* conversions to maximum values */ -#if TIME_T_MAX_BITS == 31 +#if TIME_T_MAX_BITS == 32 && !defined(TIME_T_SIGNED) { "20-Jan-2038", 2147483647 }, { "31-Dec-9999", 2147483647 }, -#elif TIME_T_MAX_BITS == 32 +#elif TIME_T_MAX_BITS == 32 && !defined(TIME_T_SIGNED) { "08-Feb-2106", 4294967295 }, { "31-Dec-9999", 4294967295 }, #endif @@ -59,8 +59,10 @@ static void test_imap_datetime(void) } tests[] = { { "01-Jan-1970 00:00:00 +0000", 0, 0 }, { "19-Jan-2038 03:14:07 +0000", 2147483647, 0 }, - { "19-Jan-2038 05:14:07 +0200", 2147483647, 2*60 }, #if TIME_T_MAX_BITS >= 32 + { "19-Jan-2038 05:14:07 +0200", 2147483647, 2*60 }, +#endif +#if TIME_T_MAX_BITS > 32 || !defined(TIME_T_SIGNED) { "07-Feb-2106 06:28:15 +0000", 4294967295, 0 }, #endif #if TIME_T_MAX_BITS >= 37 @@ -71,10 +73,10 @@ static void test_imap_datetime(void) { "31-Dec-9999 23:59:59 -2359", 253402300799LL + 23*60*60 + 59*60, -23*60 - 59 }, #endif /* conversions to maximum values */ -#if TIME_T_MAX_BITS == 31 +#if TIME_T_MAX_BITS == 32 && defined(TIME_T_SIGNED) { "19-Jan-2038 03:14:08 +0000", 2147483647, 0 }, { "31-Dec-9999 23:59:59 -2359", 2147483647, -23*60 - 59 }, -#elif TIME_T_MAX_BITS == 32 +#elif TIME_T_MAX_BITS == 32 && !defined(TIME_T_SIGNED) { "07-Feb-2106 06:28:16 +0000", 4294967295, 0 }, { "31-Dec-9999 23:59:59 -2359", 4294967295, -23*60 - 59 }, #endif